package com.hl.toolkit.app.app.config;

import java.util.List;

import javax.servlet.Registration.Dynamic;
import javax.servlet.ServletContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

import com.tycoin.AutoLoadServlet;
import com.tycoin.SpringContextHolder;

/**
 * Servlet配置
 */
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);
 
 
    @Bean
    public ViewResolver viewResolver() {
        logger.info("-------------------- ViewResolver init ---------------------");
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }
    
    
  
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/errors/bad-request").setViewName("errors/400");
        registry.addViewController("/errors/unauthorized").setViewName("errors/401");
        registry.addViewController("/errors/not-found").setViewName("errors/404");
        registry.addViewController("/errors/internal-server-error").setViewName("errors/500");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/assets/**").addResourceLocations("/assets/");
        registry.addResourceHandler("/static/**").addResourceLocations("/static/");
         registry.addResourceHandler("/theme/**").addResourceLocations("/theme/");
        registry.addResourceHandler("/swagger/**").addResourceLocations("/swagger/");
        registry.addResourceHandler("/upload/**").addResourceLocations("/upload/");
        registry.addResourceHandler("/video/**").addResourceLocations("/video/");
        registry.addResourceHandler("/image/**").addResourceLocations("/image/");
      }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new PageableHandlerMethodArgumentResolver());
    }
    
 

 
    

}
